Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

260
Vistas
im geting [object Object] but i want to get text that in tags

can somebody say how to replace it ?

function textFormat(value){
        value = value.replace(/\*{2}(.*?)\*{2}/g, <strong>{'$1'}</strong>);
        value = value.replace(/\*(.*?)\*/g, <i>{'$1'}</i>);
        value = value.replace(/~{2}(.*?)~{2}/g, <s>{'$1'}</s>);
        value = value.replace(/_{2}(.*?)_{2}/g, <u>{'$1'}</u>);
        return value;
    }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It might help if you can show how you're getting the initial value that's being passed to the textFormat() function.

But in general it looks like the function expects a text string, but the value being passed to the function is an object.

MDN docs: Object

The best approach here would probably be to adjust the code outside of the function, so that when the textFormat() function is called, the value it's called with is a text string instead of an object.

Or, a more versatile solution would be to add an input handler at the top of textFormat() to handle different kinds of input differently:

function textFormat(inVal){

    // check input type
    let value;
    if (typeof inVal === 'object') {
    
        // input is an object, so we'll turn the
        // object into a JSON string
        
        value = JSON.stringify(inVal);
        
    } else {    
    
        // input is not an object, so we'll assume
        // it's a string
        
        value = inVal;
    }

    value = value.replace(/\*{2}(.*?)\*{2}/g, <strong>{'$1'}</strong>);
    value = value.replace(/\*(.*?)\*/g, <i>{'$1'}</i>);
    value = value.replace(/~{2}(.*?)~{2}/g, <s>{'$1'}</s>);
    value = value.replace(/_{2}(.*?)_{2}/g, <u>{'$1'}</u>);
    return value;
    
}

Note, however, that with the latter solution if you input an object, the return value will be a JSON-ified string of that object (with the given string replacements performed). If you want to get back a modified object, then you'll have to turn the JSON string back into an object after the string.replace() lines.

You can do that with JSON.parse()

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda